package com.wuseguang.springcloud.service.impl;

import com.wuseguang.springcloud.dao.jdbc.RatingLimitsCustomizedJdbc;
import com.wuseguang.springcloud.dao.repository.RatingLimitsCustomizedRepository;
import com.wuseguang.springcloud.entity.RatingLimitsCustomized;
import com.wuseguang.springcloud.service.RatingLimitsCustomizedService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 教师评分限制-定制-浙江温州 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-09-27
 */
@Service
public class RatingLimitsCustomizedServiceImpl  implements RatingLimitsCustomizedService {


    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private RatingLimitsCustomizedJdbc ratingLimitsCustomizedJdbc;
    @Autowired
    private RatingLimitsCustomizedRepository ratingLimitsCustomizedRepository;


    @Override
    public Result findRatingLimitsCustomized(String schoolId) {
        logger.info("查询教师评分限制");
        String sql = "select rlc.id,rlc.teacher_id,rlc.fraction  from rating_limits_customized rlc " +
                " left join teacher t on(t.id=rlc.teacher_id) where rlc.school_id = ? ";
        List<Map<String,Object>> list = ratingLimitsCustomizedJdbc.queryListMap(sql,schoolId);
        return new Result(list);
    }

    @Override
    public Result addRatingLimitsCustomized(List<RatingLimitsCustomized> list, String schoolId) {
//        ratingLimitsCustomizedRepository.deleteBySchoolId(Integer.valueOf(schoolId));
        ratingLimitsCustomizedJdbc.updateByParameter("delete from rating_limits_customized where school_id = ?",schoolId);
        logger.info("添加教师评分限制");
        list.forEach(x->{x.setSchoolId(Integer.valueOf(schoolId));x.setSurplus(x.getFraction());});
        ratingLimitsCustomizedRepository.saveAll(list);
        return new Result();
    }
}
